function [out] = tuneRmax(x)

% global theta numpatches Dii Bij_initial domain_suit_hab max_age age_mature...
%     age_legal  Wij Rmax alpha1 delta pr max_simulation_length Fsum  hide0_show1_figures...
%      K beta_i_initial Bijy Nij TargetBiomass theta_percent

global theta  numpatches Dii   domain_suit_hab max_age age_mature...
    age_legal  Wij Rmax alpha1 delta Kvirgin  pr max_simulation_length ...
       Fsum  hide0_show1_figures K Bi_legal_fish  beta_i_initial ...
       Bij_initial TargetBiomass CRgoal theta_percent...
       FleetProfit_Fsum_op MPA_locs NPVon
 
Rmax=x;
warning off MATLAB:divideByZero
beta_i_initial=alpha1./(Rmax.*domain_suit_hab);
warning on MATLAB:divideByZero
 
    MOPmodel2
    out=TargetBiomass-K;
end
